package nina.yiyou.attendance.s10merge.compute.latepoint

import nina.yiyou.attendance.s10merge.compute.AttendDetailMerger
import nina.yiyou.salary.input.config.WorkTimeSheetReader

import java.time.LocalDate
import java.time.LocalDateTime

class LatePointCalculatorFactory {

  LatePointCalculatorFactory(AttendDetailMerger.PunchDay day, List<AttendDetailMerger.PunchDay> dayList, List<WorkTimeSheetReader.Line> workTimeCfg) {
    _day = day
    _dayList = dayList
    _workTimeCfg = workTimeCfg
  }

  LatePointCalculator create() {
    LocalDate curDate = _day.date()
    String department = _day.employee().department()

    LatePointCalculator.DefaultPoint defaultPoint = makeDefaultPoint(curDate, department)
    return new LatePointCalculator(_day, _dayList, defaultPoint)
  }

  private LatePointCalculator.DefaultPoint makeDefaultPoint(LocalDate curDate, String dept) {
    WorkTimeSheetReader.Line timeCfg = new WorkTimeFinder(_workTimeCfg, dept).findTime()

    return new LatePointCalculator.DefaultPoint() {
      @Override
      LocalDateTime amIn() {
        return curDate.atTime(timeCfg.amIn())
      }

      @Override
      LocalDateTime amOut() {
        return curDate.atTime(12, 30)
      }

      @Override
      LocalDateTime pmIn() {
        return curDate.atTime(14, 00)
      }
    }
  }

  private final AttendDetailMerger.PunchDay _day

  private final List<AttendDetailMerger.PunchDay> _dayList
  private final List<WorkTimeSheetReader.Line> _workTimeCfg
}
